/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.cheln.explorer.ds.database.copersynch;

import android.content.Context;
import android.net.Uri;
import android.provider.MediaStore;

import cn.cheln.explorer.beans.FileInfo;
import cn.cheln.explorer.beans.FileUtil;
import cn.cheln.explorer.config.Constants;
import cn.cheln.explorer.ds.MediaArgs;
import cn.cheln.support.images.MimeTypeMap;

/**
 * 
 * @author Administrator
 */
public class DatasrcDelete {

	public static void recursiveUpdateDel(FileInfo info, Context context) {
		String ext;
		String mime;
		// String mimeprefix = null;
		Uri uri = null;
		ext = FileUtil.getRealExtension(info.getName());

		mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(
				ext.toLowerCase());
        info.buildFile();
		if (info.isDir||info.getFile().isDirectory()) {
			uri = MediaArgs.dirUri;
		} else {
			if (mime == null) {

				return;
			}

			if (mime.startsWith(Constants.CateContants.CATE_IMAGES)) {
				uri = MediaArgs.ImageUri;
				// mimeprefix = Constants.CateContants.CATE_IMAGES;
			} else if (mime.startsWith(Constants.CateContants.CATE_MUSIC)) {
				uri = MediaArgs.AudioUri;
				// mimeprefix = Constants.CateContants.CATE_MUSIC;
			} else if (mime.startsWith(Constants.CateContants.CATE_VIDEO)) {
				uri = MediaArgs.VideoUri;
				// mimeprefix = Constants.CateContants.CATE_VIDEO;
			} else {
				if (info.getName().trim().toLowerCase()
						.endsWith(Constants.LOWERCASE_APK)) {
					// mimeprefix = Constants.CateContants.CATE_PACKAGE;
					uri = MediaArgs.otherUri;
				} else if (mime
						.startsWith(Constants.MIMEContants.MIME_APPLICATION)
						|| mime.startsWith(Constants.MIMEContants.MIME_TEXT)) {
					// mimeprefix = Constants.CateContants.CATE_DOCS;
					uri = MediaArgs.otherUri;
				} else if (info.name.trim().toLowerCase()
						.endsWith(Constants.LOWERCASE_LWT)) {
					// mimeprefix = Constants.CateContants.CATE_THEME;
					uri = MediaArgs.otherUri;
				}

			}
		}
		if (uri != null) {
//			if(Config.is4_0Lower){
//				context.getContentResolver().delete(uri,
//						MediaStore.Audio.Media.DATA + " like ?",
//						new String[] { info.getPath() });
//			}else{
				context.getContentResolver().delete(uri,
						MediaStore.Audio.Media.DATA + " like ?",
						new String[] { info.getPath() });
//			}
			
		}
	}

}
